/**
 * Created by Francis.LW on 2017/10/20.
 *
 * 角色服务接口
 */
import {postRequest, getRequest} from '@/common/request'
import {urls} from './url'

const roleApi = urls.role

/**
 * 获取所有角色
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listAllRole(success, complete) {
  postRequest(roleApi.listAllRole,{},{}, success, complete)
}

/**
 * 获取所有代理商角色
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listAgentsAllRole(success, complete) {
  postRequest(roleApi.listAgentsAllRole,{},{}, success, complete)
}

/**
 * 获取角色列表
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listRole(param, page, pageSize, success, complete) {
  postRequest(roleApi.listRole + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

function listServiceRole(param, page, pageSize, success, complete) {
  postRequest(roleApi.listServiceRole + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

/**
 * 创建新角色
 * @param param
 * @param success
 * @param complete
 */
function addRole(param, success, complete) {
  postRequest(roleApi.addRole, {}, param, success, complete)
}

function addServicePrivoderRole(param, success, complete) {
  postRequest(roleApi.addServicePrivoderRole, {}, param, success, complete)
}

/**
 * 更新角色信息
 * @param id
 * @param param
 * @param success
 * @param complete
 */
function updateRole(id, param, success, complete) {
  postRequest(roleApi.updateRole + id, {}, param, success, complete)
}

/**
 * 获取角色信息
 * @param id
 * @param success
 * @param complete
 */
function getRoleById(id, success, complete) {
  getRequest(roleApi.getRoleById + id, {}, success, complete)
}

/**
 * 删除角色信息
 * @param ids
 * @param success
 * @param complete
 */
function deleteRole(ids, success, complete) {
  postRequest(roleApi.removeRole, {}, ids, success, complete)
}

/**
 *
 * @param ids
 * @param success
 * @param complete
 */
function deleteSingleRole(id, success, complete) {
  let ids = []
  ids.push(id)
  deleteRole(ids, success, complete)
}

export default {
  listRole,
  listAllRole,
  listServiceRole,
  addServicePrivoderRole,
  addRole,
  updateRole,
  getRoleById,
  deleteRole,
  deleteSingleRole,
  listAgentsAllRole
}
